package br.com.maiscontrole.view.site.beans.data;

import java.util.Calendar;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import br.com.maiscontrole.view.site.beans.abst.AbstractMB;
import br.com.maiscontrole.view.site.navigator.NavigatorRules;

/**
 * 
 * @author milton
 *
 */
@ManagedBean(name = "dataMB")
@SessionScoped
public class DataMB extends AbstractMB{

	public static void main(String[] args) {

	}

	private DataMDV dataMDV;


	public DataMB() {

	}

	public String consultar(){
		this.getDataMDV().limpar();
		Calendar calendar = Calendar.getInstance();
		this.getDataMDV().setCalendar(calendar);
		this.getDataMDV().consultarMontarData(calendar);
		return NavigatorRules.DATA_LIST;
	}

	public String consultarCalendarioAnterior(){
		this.consultarCalendarioPag(-1);
		return NavigatorRules.DATA_LIST;
	}

	private void consultarCalendarioPag(int proximoAnt){
		this.getDataMDV().getCalendar().add(Calendar.MONTH, proximoAnt);
		this.getDataMDV().getList().clear();
		this.getDataMDV().consultarMontarData(this.getDataMDV().getCalendar());
	}

	public String consultarCalendarioProximo(){
		this.consultarCalendarioPag(1);
		return NavigatorRules.DATA_LIST;
	}

	public DataMDV getDataMDV() {
		return this.dataMDV;
	}

	@PostConstruct
	@Override
	public void setarDados() {
		this.dataMDV = new DataMDV(this.getFacade());
	}

	public void setDataMDV(DataMDV dataMDV) {
		this.dataMDV = dataMDV;
	}

}
